#!/bin/bash

# create WAL, DB Disk partitions
    # fdisk /dev/sdb
    # new partition > extended type
    # /dev/sdb5, /dev/sdb6, /dev/sdb7, /dev/sdb8

# create all OSDs
    # ceph-volume lvm create --block.wal /dev/sdb5 --block.db /dev/sdb6 --data /dev/sdc
    # ceph-volume lvm create --block.wal /dev/sdb7 --block.db /dev/sdb8 --data /dev/sdd

members=("node1" "node2" "node3")
pub_addr=("172.24.16.245" "172.24.16.246" "172.24.16.247")
cls_addr=("172.24.0.245" "172.24.0.246" "172.24.0.247")
#---------------- All ceph nodes update ceph.conf -----------------------
for((i=0; i<${#members[@]}; i++))
do
for((j=0; j<${#members[@]}; j++))
do
    cmd="echo ' ' >> /etc/ceph/ceph.conf"; ssh root@${members[$i]} $cmd
        cmd="echo '[osd.$j]' >> /etc/ceph/ceph.conf"; ssh root@${members[$i]} $cmd
        cmd="echo 'host = ${members[$j]}' >> /etc/ceph/ceph.conf"; ssh root@${members[$i]} $cmd
        cmd="echo 'public_addr = ${pub_addr[$j]}' >> /etc/ceph/ceph.conf"; ssh root@${members[$i]} $cmd
        cmd="echo 'cluster_addr = ${cls_addr[$j]}' >> /etc/ceph/ceph.conf";    ssh root@${members[$i]} $cmd
    cmd="echo ' ' >> /etc/ceph/ceph.conf"; ssh root@${members[$i]} $cmd
done
done

#------------------------------------------------------------------------
for((i=0; i<${#members[@]}; i++))
do
    cmd="systemctl restart ceph-mon@${members[$i]}"; ssh root@${members[$i]} $cmd
    cmd="systemctl restart ceph-mgr@${members[$i]}"; ssh root@${members[$i]} $cmd
    cmd="systemctl restart ceph-mds@${members[$i]}"; ssh root@${members[$i]} $cmd
done

## restart all nodes' OSDs